package com.gome.ss.webserver.servlet.api;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jdom2.JDOMException;

import com.gome.ss.common.AppConfiguer;
import com.gome.ss.core.plugin.PluginManager;
import com.gome.ss.core.plugin.SpiderLocalPluginConfig;
import com.gome.ss.flowcrawl.plugin.FlowCrawlManager;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class FlowCrawlLoad extends HttpServlet {

	/* /spiderkit/flowcrawl_info */
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String pluginNameString = req.getParameter("pluginName");
		
		resp.setContentType("text/html;charset=gbk");
		req.setCharacterEncoding("gbk");
		
		resp.getWriter().print(String.valueOf(FlowCrawlManager.load(pluginNameString)));
		resp.getWriter().close();
	}
	
	private BasicDBObject getLike(String findStr) {
		Pattern pattern = Pattern.compile("^.*" + findStr + ".*$", Pattern.MULTILINE);
	    return new BasicDBObject("$regex", pattern);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}

}
